import java.util.HashMap;
import java.util.Map;

public class Test02 {
    public int lengthOfLongestSubstring(String s) {
        Map<Character,Integer> window = new HashMap<>();
        int left = 0,right = 0;
        int res = 0;
        while(right < s.length()){
            /*窗口扩大并更新window中的内容*/
            char c = s.charAt(right);
            right++;
            window.put(c, window.getOrDefault(c,0)+1);
            /*然后对window中的数据进行判断：是否要缩小窗口*/
            while(window.get(c) > 1){
                /*缩小窗口并更新元素*/
                char d = s.charAt(left);
                left++;
                window.put(d,window.get(d) - 1);
            }
            /*记录最大连续值*/
            res = Math.max(res,right - left);
        }
        return res;
    }
}
